home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / chasm01.sha / sample.ch < prev   
Text File  |  1995-03-23  |  2KB  |  72 lines

  1. / This is a sample chasm file. It doesn't do an awful lot, but makes
  2. / a good example. Keep in mind that this is pretty much of a hack.
  3. / The only key used by the program is "+".
  4.  
  5. / Registers used:
  6. /    V0 - scratch
  7. /    V1 - keypress flag
  8. /    V2 - key comparison
  9. /    V3 - sprite x
  10. /    V4 - sprite y
  11. /    V5 - sad/smile flag
  12. /    V6 - scratch
  13. /    V7 - scratch
  14.  
  15.     jmp start            / jump over the data
  16.     data "By Steve Scherf"        / this shows up for all to see
  17.  
  18. start:
  19.     cld                / blank the screen
  20.     mov 0, V1            / initialize keypress flag
  21.     mov 0xF, V2            / this is the plus key
  22.     mov 32, V3            / initialize x coord
  23.     mov 16, V4            / initialize y coord
  24.     mov 0, V5            / initialize smiley flag
  25.     mov sprite, I            / set pointer to sprite
  26.     dsp 6, V3, V4            / display the sprite
  27. loop:
  28.     jsr get_key            / check for keyboard input
  29.     mov dtimer, V0            / copy dtimer to V0
  30.     sne 0, V0            / is it time to move sprite?
  31.     jsr move_sprite            / do so if it is time
  32.     jmp loop            / go back to top
  33.  
  34. / don't fall through here
  35.  
  36. get_key:
  37.     mov 0, V7            / clear V7
  38.     snp V2                / check for the "+" key
  39.     mov 1, V7            / set V7 to true if pressed
  40.     mov V1, V6            / set V6 to old value of keypress flag
  41.     mov V7, V1            / set keypress flag accordingly
  42.  
  43.     seq 1, V7            / is the key pressed?
  44.     ret                / return if not
  45.     sne 1, V6            / if V6 is true, key has not been lifted
  46.     ret                / return if not lifted
  47.  
  48.     mov 1, V6
  49.     mov V6, stimer            / beep for 1/60th second
  50.     mov 1, V6
  51.     xor V6, V5            / toggle smile/sad flag
  52.     dsp 6, V3, V4            / clear the old sprite
  53.     mov sprite, I            / point I to the new sprite
  54.     mov 6, V6
  55.     seq 0, V5            / is this the second sprite?
  56.     add V6, I            / point I to the second sprite
  57.     dsp 6, V3, V4            / display the new sprite
  58.     ret
  59.  
  60. move_sprite:
  61.     dsp 6, V3, V4            / clear the old sprite
  62.     add 1, V3            / compute new coords
  63.     add 255, V4            / this is the same as subtracting 1
  64.     dsp 6, V3, V4            / display the sprite at new coords
  65.     mov 15, V0            / we can only set timer from a register
  66.     mov V0, dtimer            / set timer for 1/4 second
  67.     ret
  68.  
  69. sprite:
  70.     data 0x66, 0x66, 0x00, 0x00, 0x42, 0x3C        / smiley sprite
  71.     data 0x66, 0x66, 0x00, 0x00, 0x3C, 0x42        / sad sprite
  72.